package osx.mantianx.wirte;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.UUID;

/**
 * @author starrysky
 * @title: PoiBigTableV07First
 * @projectName Excel_Poi_EasyExcel
 * @description: TODO
 * @date 2021/2/410:19
 */
public class PoiBigTableV07First {
    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        SXSSFWorkbook workbook = new SXSSFWorkbook();
        Sheet sheet = workbook.createSheet("数字矩阵表");

        for (int rowNumber = 0; rowNumber < 65536; rowNumber++) {
            Row row = sheet.createRow(rowNumber);
            if (rowNumber!=0){
                for (int colNumber = 0; colNumber < 6; colNumber++) {
                    Cell cell = row.createCell(colNumber);
                    cell.setCellValue(UUID.randomUUID().toString().substring(0,5));
                }
            }else {
                for (int colNumber = 0; colNumber < 6; colNumber++) {
                    Cell cell = row.createCell(colNumber);
                    cell.setCellValue("入账信息");
                }
            }
        }
        FileOutputStream xlsBigTablesV03 = null;
        try {
            xlsBigTablesV03 = new FileOutputStream("XlsBigTablesV07First.xls");
            workbook.write(xlsBigTablesV03);
            System.out.println("写入完毕");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (xlsBigTablesV03!=null){
                try {
                    xlsBigTablesV03.close();
                    workbook.close();
                    //关闭清理临时文件
                    workbook.dispose();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        long endTime = System.currentTimeMillis();
        System.out.println("耗时总时间"+(double)(endTime-startTime)/1000);
    }
}
